<template>
    <div class="box">
        <i-table ref="myTable" :search="getSearch" :table="getTbale" :pageConfig="pageConfig" @resetTable="ResetTable">
            <template slot-scope="{ dataS }" slot="type">
                <Tag v-if="dataS.type == 0">国家法律</Tag>
                <Tag v-if="dataS.type == 1">政策解读</Tag>
                <Tag v-if="dataS.type == 2">行政法规</Tag>
                <Tag v-if="dataS.type == 3">部门规章</Tag>
            </template>
        </i-table>
        <Modal v-model="modalShow" width="1200" :mask-closable="false" :title="modalTitle">
            <components v-if="modalShow" :is="comps" ref="coms" />
            <div slot="footer">
                <Button v-if="infoshow" type="text" @click="cancel">取消</Button>
                <Button v-if="infoshow" type="primary" @click="ok">确定</Button>
            </div>
        </Modal>
    </div>
</template>
<script>
import { config } from './policyPage_config'
import policyAddUpdata from "./policyPage-add-updata.vue"
export default {
    name: '',
    props: [''],
    data() {
        return {
            search: {}, // 查询配置对象
            tableConfig: {}, // 表格配置对象
            pageConfig: config.page, // 翻页器配置
            comps: policyAddUpdata,
            modalShow: false,
            modalTitle: '',
            infoshow: true
        };
    },
    components: {},
    computed: {
        getSearch() {
            this.search = icu.util.deepClone(config.search);// 为不改变原始配置数据，进行深度克隆。
            return this.search;
        },
        getTbale() {
            this.tableConfig = icu.util.deepClone(config.table); // 深度克隆表格配置。
            this.tableConfig.event = {
                info: this.info,
                edit: this.edit,
                add: this.add,
                release: this.release,
                remove: this.remove,
                zdy: this.zdy
            }
            return this.tableConfig;
        }
    },
    beforeMount() { },
    mounted() { },
    methods: {
        add(row) {
            this.infoshow = true
            this.modalShow = true
            this.modalTitle = '新增'
        },
        edit(event, row) {
            this.infoshow = true
            this.modalShow = true
            this.modalTitle = '编辑'
            this.$nextTick(() => {
                this.$refs.coms.setData(row, 'edit')
            })
        },
        ok() {
            this.$refs.coms.getForm((formRes) => {
                this.modalShow = false
                this.modalTitle = ''
                this.ResetTable()
            })
        },
        cancel() {
            this.modalShow = false
            this.modalTitle = ''
        },
        info(event, row) {
            this.infoshow = false
            this.modalShow = true
            this.modalTitle = '查看'
            this.$nextTick(() => {
                this.$refs.coms.setData(row, 'info')
            })
        },
        remove(event, row) {
            this.$Modal.confirm({
                title: '删除确认',
                content: '确认删除该条数据？',
                onOk: () => {
                    this.$http.$post('InformationDelete', { data: [row.id] }).then(res => {
                        if (res.code == 200) {
                            this.$Message.success('删除成功');
                            this.ResetTable()
                            return
                        }
                        this.$Message.error(res.msg);
                    })
                },
            });
        },
        release(row) {
            this.$Modal.confirm({
                title: '是否确认发布？',
                onOk: () => {
                    this.$http.$get('InformationRelease', { params: { id: row.id } }).then(res => {
                        if (res.code == 200) {
                            this.$Message.success('发布成功');
                            this.ResetTable()
                            return
                        }
                        this.$Message.error(res.msg);
                    })
                },
                onCancel: () => {
                    this.$Message.info('已取消');
                }
            });
        },
        back(row) {
            this.$Modal.confirm({
                title: '是否撤销发布？',
                onOk: () => {
                    this.$http.$get('InformationCancelRelease', { params: { id: row.id } }).then(res => {
                        if (res.code == 200) {
                            this.$Message.success('撤销成功');
                            this.ResetTable()
                            return
                        }
                        this.$Message.error(res.msg);
                    })
                },
                onCancel: () => {
                    this.$Message.info('已取消');
                }
            });
        },
        ResetTable() {
            this.$refs.myTable.seach()
        },
        zdy(value, row) {
            switch (value) {
                case 'looklook':
                    this.info(null, row)
                    break;
                case 'edit':
                    this.edit(null, row)
                    break;
                case 'publish':
                    this.release(row)
                    break;
                case 'back':
                    this.back(row)
                    break;
                case 'delete':
                    this.remove(null, row)
                    break;
            }
        }
    },
    watch: {}
}
</script>
<style lang='less' scoped>
.box {
    background: #eee;
    height: 100%;
}
.info-card {
    height: 100%;
}
</style>